﻿using System;
using System.Collections.Generic;
using System.Text;
using FireBillBook.Core.Models;
using Microsoft.Extensions.DependencyInjection;
using System.Linq;

namespace FireBillBook.Core.Services
{
    public class PlatformServiceBuilder : IPlatformServiceBuilder
    {
        public IServiceCollection Services { get; set; }

        public PlatformServiceInfoCollection PlatformServiceInfos { get; set; } = new PlatformServiceInfoCollection();

        public PlatformServiceBuilder(IServiceCollection services)
        {
            Services = services;
        }

        public void AddServiceInfo(string key, string description)
        {
            if(string.IsNullOrEmpty(key))
            {
                throw new ArgumentNullException($"未指定键值");
            }

            if (PlatformServiceInfos == null) PlatformServiceInfos = new PlatformServiceInfoCollection();

            if(!PlatformServiceInfos.TryAdd(new PlatformServiceInfo(key, description)))
            {
                throw new ArgumentException($"{nameof(PlatformServiceInfos)}已存在相同的键: {key}");
            }
        }
    }
}
